<title>统计管理</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a><cite>日志管理</cite></a>
        <a href="#/statistics/index/"><cite>统计管理</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">统计管理</div>
        <div class="layui-card-body">
            <div class="layui-form"  lay-filter="log-statistics-index-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="sdate" class="layui-input" id="lssdate" placeholder="开始时间" style="display: inline;width: 26%;">
                        <span>-</span>
                        <input type="text" name="edate" class="layui-input" id="lsedate" placeholder="结束时间" style="display: inline;width: 26%;">
                        <input type="text" name="name" class="layui-input" placeholder="姓名" style="display: inline;width: 25%;">
                        <button class="layui-btn" lay-submit lay-filter="log-statistics-index-form-submit" style="margin-left: 10px;">立即搜索</button>
                        <div style="width: 300px;height: 35px;margin-top:20px;">
                            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="log-statistics-index-lastWeek-form-submit">上周</button>
                            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="log-statistics-index-thisWeek-form-submit">本周</button>
                            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="log-statistics-index-lastMonth-form-submit">上月</button>
                            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-submit lay-filter="log-statistics-index-thisMonth-form-submit">本月</button>
                        </div>
                    </div>
                </div>
            </div>
            <table id="log-statistics-index-table" lay-filter="log-statistics-index-table" class="tables"></table>
        </div>
    </div>
</div>

<script>
    layui.use(['laydate', 'form', 'table', 'admin','jquery'], function(){
        var laydate = layui.laydate
            ,table = layui.table
            ,form = layui.form
            ,admin = layui.admin
            ,$=layui.jquery;
        //执行一个laydate实例
        laydate.render({
            elem: '#lssdate'
        });
        laydate.render({
            elem: '#lsedate'
        });

        form.render(null, 'log-statistics-index-form');
        table.render({
            elem: '#log-statistics-index-table'
            ,url: layui.cache.baseapi + '/api/log.Statistics/index'
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'name', title: '姓名', align: 'center'}
                ,{field:'number', title: '日志次数',width: 400}
            ]],
        });

        //监听搜索
        form.on('submit', function(data){
            var field = data.field, date = '' ;
            if (data.elem.innerText == '上周') {
                field.sdate = '';
                field.edate = '';
                date = 'lastWeek';
            } else if (data.elem.innerText == '本周') {
                field.sdate = '';
                field.edate = '';
                date = 'thisWeek';
            } else if (data.elem.innerText == '上月') {
                field.sdate = '';
                field.edate = '';
                date = 'lastMonth';
            } else if (data.elem.innerText == '本月') {
                field.sdate = '';
                field.edate = '';
                date = 'thisMonth';
            }
            field.date = date;
            //执行重载
            table.reload('log-statistics-index-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: field
            });
            laydate.render({
                elem: '#lssdate'
            });
            laydate.render({
                elem: '#lsedate'
            });
        });
    });
</script>